
// <-------异步加载操作

const User = resolve => {
    require.ensure(['./views/user/User.vue'],()=>{
        resolve(require('./views/user/User.vue'))
    },'user')   //user为自定义的模块名，下面为同一个大的模块
}
const UserStart = resolve=>{
    require.ensure(['./views/user/UserStart.vue'],()=>{
        resolve(require('./views/user/UserStart.vue'))
    },'user')
}
const UserEdit = resolve=>{
    require.ensure(['./views/user/UserEdit.vue'],()=>{
        resolve(require('./views/user/UserEdit.vue'))
    },'user')
}

const UserDetail = resolve=>{
    require.ensure(['./views/user/UserDetail.vue'],()=>{
        resolve(require('./views/user/UserDetail.vue'))
    },'user')
}

const Cate = resolve => {
    require.ensure(['./views/cate/Cate.vue'],()=>{
        resolve(require('./views/cate/Cate.vue'))
    },'cate')
}
const News = resolve => {
    require.ensure(['./views/news/News.vue'],()=>{
        resolve(require('./views/news/News.vue'))
    },'news')
}
const Upload = resolve => {
    require.ensure(['./views/upload/Upload.vue'],()=>{
        resolve(require('./views/upload/Upload.vue'))
    },'upload')
} 
const Product = resolve => {
    require.ensure(['./views/product/Product.vue'],()=>{
        resolve(require('./views/product/Product.vue'))
    },'product')
} 

//异步加载操作--------->}

const routers = [
    {
        path: '/',
        meta: {
            title: ''
        },
        component: (resolve) => require(['./views/Home.vue'], resolve)
    },
    {//用户
        path:'/user',
        components:{
            default:User,
        }
        ,children:[// /user      user下的模块
        {path:"",component:UserStart},// /user/
        {path:":id",component:UserDetail,beforeEnter: (to, from, next) => {
            consloe.log('route.........')
            next();
        }},// /user/:id
        {path:":id/edit",component:UserEdit,name:'userEdit'}// /user/:id/edit
    ]},
    {//分类
        path: '/cate',
        meta: {
            title: ''
        },
        component: (resolve) => require(['./views/cate/Cate.vue'], resolve)
    },
    {//新闻
        path: '/news',
        meta: {
            title: ''
        },
        component: (resolve) => require(['./views/news/News.vue'], resolve)
    },
    {//上传
        path: '/upload',
        meta: {
            title: ''
        },
        component: (resolve) => require(['./views/upload/Upload.vue'], resolve)
    },
     {//产品
        path: '/product',
        meta: {
            title: ''
        },
        component: (resolve) => require(['./views/product/Product.vue'], resolve)
    },
    //重定向   path为url栏里输入的地址
    {
        path:'/redirecct-me',redirect:'/user'//redirect后的为要跳转到的url地址
    },
    {
        path:'/redirect-you',redirect:{name:'home'}//name为定义的跳转地址的name值
    },
    {
        path:'*',redirect:'/'//输入其他任意的url地址都匹配到首页
    }
];
export default routers;